package com.simple.controller;

import com.simple.common.Result;
import com.simple.dto.UserDTO;
import com.simple.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName UserController
 * @Author SimpleTree
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public Result login(@RequestBody UserDTO userDTO) {
        return userService.login(userDTO);
    }

    @GetMapping
    public Result getUsers(UserDTO userDTO) {
        return Result.of(userService.getUsers(userDTO));
    }

    @GetMapping("/getUserById/{id}")
    public Result getUserById(@PathVariable("id")Integer id) {
        return Result.of(userService.getUserById(id));
    }

    @PutMapping
    public Result updateUser(@RequestBody UserDTO userDTO) {
        userService.updateUser(userDTO);
        return Result.of();
    }

}
